package Top200;

/**
 * @author zhangmin
 * @create 2022-02-18 9:28
 * 双指针：每次收缩较小的一边
 */
public class maxArea11 {
    public int maxArea(int[] height) {
        int n=height.length;
        int left=0,right=n-1,res=0;
        while (left<right){
            int cur=Math.min(height[left],height[right])*(right-left);
            res=Math.max(res,cur);
            if (height[left]<height[right]){
                left++;
            }else {
                right--;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        maxArea11 obj=new maxArea11();
        int[] height= {1, 8, 6, 2, 5, 4, 8, 3, 7};
        System.out.println(obj.maxArea(height));
    }
}
